package sweet.helper.container

import java.io.{ File, InputStream, FileInputStream }
import java.{ util=> jutil }
import scala.collection.{ mutable, immutable, jcl }
import StringHelper._

/** A trait that provide init/destroy life cycle.
 *
 * When using as stackble chain of initialization for an objects
 * with multiple sub trait of this, the sub trait MUST <code>override</code> 
 * #init or #destroy, and MUST calls #super.init to chain ALL 
 * linear initialization.
 *
 * Example:
 * <pre>
 *   trait T1 extends InitDestroy { override def init{ super.init; println("T1 stuff goes here") }
 *   trait T2 extends InitDestroy { override def init{ super.init; println("T2 stuff goes here") }
 *   class MyInitializer extends Object with T1 with T2
 *   new MyInitializer().init //<-- will call both T1 and T2 init methods!
 * </pre>
 */
trait InitDestroy {
  def init{}
  def destroy{}  
}

/** A container for InitDestroy.
 *
 * This trait is provide alternative solution to collect all InitDestroy instances
 * then perform custom codes. 
 */
trait InitDestroyContainer {
  def initsDestroys = _initsDestroys.toList
  val _initsDestroys = new mutable.ListBuffer[InitDestroy]
  
  /** abstract control to add initializable container */
  def initsDestroys(xs: InitDestroy*){ _initsDestroys ++= xs }
}

